package com.zmc.product.controller;

import com.zmc.common.domain.vo.good.GoodsInventoryVo;
import com.zmc.common.domain.vo.good.GoodsUpVo;
import com.zmc.common.domain.vo.inventory.InventoryDeleteVo;
import com.zmc.common.domain.vo.inventory.InventoryInitVo;
import com.zmc.common.utils.R;
import com.zmc.product.infrastructure.entity.InventoryGoodsStockEntity;
import com.zmc.product.infrastructure.service.InventoryGoodsStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 库存中心的商品库存表
 *
 * @author zmc
 * @email 
 * @date 2024-11-28 14:03:53
 */
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private InventoryGoodsStockService inventoryGoodsStockService;


    /**
     * 信息
     */
    @PostMapping("/info")
    public R info(@RequestBody InventoryInitVo vo){
        return R.ok(inventoryGoodsStockService.getBySkuId(vo.getSkuId()));
    }

    /**
     * 保存
     */
    @PostMapping("/add")
    public R save(@RequestBody InventoryInitVo vo){
		inventoryGoodsStockService.saveInventory(vo);
        return R.ok();
    }

    /**
     * 修改(可直接修改库存：仅更新出售库存)
     */
    @PostMapping("/update")
    public R update(@RequestBody InventoryGoodsStockEntity inventoryGoodsStock){
        InventoryGoodsStockEntity update = new InventoryGoodsStockEntity();
        update.setId(inventoryGoodsStock.getId());
        update.setSaleStockQuantity(inventoryGoodsStock.getSaleStockQuantity());
		inventoryGoodsStockService.updateById(update);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    public R remove(@RequestBody InventoryDeleteVo vo){
        inventoryGoodsStockService.deleteBySkuId(vo.getSkuId());
        return R.ok();
    }

    /**
     * 商品入库
     */
    @PostMapping("/storage")
    public R storage(@RequestBody List<GoodsUpVo> list){
        inventoryGoodsStockService.upToInventory(list);
        return R.ok();
    }

    /**
     * 下单：锁定库存
     */
    @PostMapping("/lock")
    public R lockStock(@RequestBody List<GoodsUpVo> list){
        return R.ok(inventoryGoodsStockService.lockStock(list));
    }


    /**
     * 已支付：扣减库存
     */
    @PostMapping("/reduce")
    public R reduceStock(@RequestBody List<GoodsUpVo> list){
        inventoryGoodsStockService.reduceStock(list);
        return R.ok();
    }

    /**
     * 订单取消、超时 =》返库存
     */
    @PostMapping("/unlock")
    public R unlockStock(@RequestBody List<GoodsUpVo> list){
        inventoryGoodsStockService.unlockStock(list);
        return R.ok();
    }

    /**
     * 申请退款：返扣减库存
     */
    @PostMapping("/return")
    public R returnStock(@RequestBody List<GoodsUpVo> list){
        inventoryGoodsStockService.returnStock(list);
        return R.ok();
    }

    /**
     * 检查库存
     */
    @PostMapping("/check")
    public R check(@RequestBody GoodsInventoryVo vo){
        return R.ok(inventoryGoodsStockService.check(vo));
    }



}
